package cn.iocoder.yudao.module.train.dal.mysql.trade;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.train.dal.dataobject.trade.TradeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.train.controller.admin.trade.vo.*;

/**
 * 交易 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface TradeMapper extends BaseMapperX<TradeDO> {

    default PageResult<TradeDO> selectPage(TradePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TradeDO>()
                .eqIfPresent(TradeDO::getTradeSn, reqVO.getTradeSn())
                .eqIfPresent(TradeDO::getWxUserId, reqVO.getWxUserId())
                .eqIfPresent(TradeDO::getPayAmount, reqVO.getPayAmount())
                .eqIfPresent(TradeDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TradeDO::getTradeNo, reqVO.getTradeNo())
                .betweenIfPresent(TradeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TradeDO::getId));
    }

    default TradeDO selectByTradeSn(String tradeSn) {
        return selectOne(new LambdaQueryWrapperX<TradeDO>()
                .eqIfPresent(TradeDO::getTradeSn, tradeSn));
    }
}
